import rclpy  
from rclpy.node import Node  
from std_msgs.msg import Int32  
import time  
  
class Talker(Node):  
    def __init__(self):  
        super().__init__('talker')  
        self.publisher_ = self.create_publisher(Int32, 'chatter', 10)  
        self.timer_period = 1  # seconds  
        self.timer = self.create_timer(self.timer_period, self.timer_callback)  
        self.call_count = 0  # 初始化调用计数器  
  
    def timer_callback(self):  
        self.call_count += 1  # 每次回调时增加计数器  
        msg = Int32()  
        msg.data = self.call_count  # 使用计数器作为消息数据  
        self.get_logger().info('Publishing: "test2%d"' % msg.data)  
        self.publisher_.publish(msg)
  
def main(args=None):  
    rclpy.init(args=args)  
    talker = Talker()  
    try:
        rclpy.spin(talker)  
    except:
        print("Exception caught. Shutting down.")   
    talker.destroy_node()  
    rclpy.shutdown()  
  
if __name__ == '__main__':  
    main()